package com.yijiaganxi.services.web.merchantsExplain;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yijiaganxi.common.entity.banner.YjgxBanner;
import org.yijiaganxi.common.entity.merchantsExplain.YjgxMerchantsExplain;
import org.yijiaganxi.common.res.R;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.yijiaganxi.common.GlobalConstants;
import com.yijiaganxi.services.service.merchantsExplain.YjgxMerchantsExplainService;

import java.util.Date;

import javax.validation.constraints.NotBlank;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;

/**
 * <p>
 * 商家说明 前端控制器
 * </p>
 *
 * @author zhangguowei123
 * @since 2020-08-29
 */
@Validated
@RestController
@RequestMapping("/services/yjgxMerchantsExplain/"+GlobalConstants.WEB_FLAG)
public class YjgxMerchantsExplainController {

	@Autowired
	public YjgxMerchantsExplainService  merchantsExplainService;
	
	/**
	 * 获取所有商家说明
	 * @return
	 */
	@GetMapping("getAllMerhantsExplainList")
	public R getAllMerhantsExplainList() {
		return R.opertionListResponse( merchantsExplainService.selectList(new EntityWrapper<YjgxMerchantsExplain>()));
	}
	
	/**
	 * 添加商家说明
	 * @param banner
	 * @return
	 */
	@PostMapping("addMerhantsExplain")
	public R addMerhantsExplain(@Validated YjgxMerchantsExplain merchainsExplain) {
		return R.insertOrUpdateResponse(merchantsExplainService.insert(merchainsExplain));
	}
	
	/**
	 * 更新商家说明
	 * @param banner
	 * @return
	 */
	@PostMapping("updateMerchainsExplain")
	public R updateMerchainsExplain(YjgxMerchantsExplain merchainsExplain) {
		if(merchainsExplain.getId()==null)
			return R.error("Id 更新操作必填");
		merchainsExplain.setModifyDate(new Date());
		return R.insertOrUpdateResponse(merchantsExplainService.update(merchainsExplain, new EntityWrapper<YjgxMerchantsExplain>()
				.eq("id", merchainsExplain.getId())));
	}
	
	/**
	 * 删除商家说明
	 * @param id
	 * @return
	 */
	@PostMapping("deleteMerchainsExplain")
	public R deleteMerchainsExplain(@NotBlank(message = "id不能为空") String id) {
		return R.insertOrUpdateResponse(merchantsExplainService.deleteById(id));
	}
	
}

